package com.bwie.home.backstage.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bwie.home.backstage.entity.HousesPhotoEntity;
import com.bwie.home.backstage.service.HousesPhotoService;
import com.bwie.home.common.utils.PageUtils;
import com.bwie.home.common.utils.R;



/**
 * 
 *
 * @author sy
 * @email sunlightcs@gmail.com
 * @date 2021-09-10 09:46:41
 */
@RestController
@RequestMapping("backstage/housesphoto")
public class HousesPhotoController {
    @Autowired
    private HousesPhotoService housesPhotoService;


    //回显楼盘相册信息
    @RequestMapping("/xiangce/{housesId}")
    public R xiangce(@PathVariable("housesId") Integer housesId){
        List<HousesPhotoEntity> housesPhoto = housesPhotoService.list(new QueryWrapper<HousesPhotoEntity>().eq("houses_id", housesId));


        return R.ok().put("list", housesPhoto);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = housesPhotoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{photoId}")
    public R info(@PathVariable("photoId") Integer photoId){
		HousesPhotoEntity housesPhoto = housesPhotoService.getById(photoId);

        return R.ok().put("housesPhoto", housesPhoto);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody HousesPhotoEntity housesPhoto){
		housesPhotoService.save(housesPhoto);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody HousesPhotoEntity housesPhoto){
		housesPhotoService.updateById(housesPhoto);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] photoIds){
		housesPhotoService.removeByIds(Arrays.asList(photoIds));

        return R.ok();
    }

}
